﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GBMS.DAL;
using KPIS.GERP.GBMS.MODEL;
using KPIS.GERP.GBMS.DALFactory;
using KPIS.GERP.GBMS.IBLL;

namespace KPIS.GERP.GBMS.BLL
{
    public class ExpenseGroupBLL : IExpenseGroupBLL
    {
        private static readonly ISourceDAL src = DataAccess.CreateSource();
        private static readonly ISourceTypeDAL srcType = DataAccess.CreateSourceType();
        private static readonly IExpenseGroupDAL dal = DataAccess.CreateExpenseGroup();

        public ExpenseGroupBLL()
        {

        }

        public IList<TreeViewInfo> TreeView(IList<TreeViewInfo> tView, bool isRootNode)
        {
            IList<TreeViewInfo> treeView = new List<TreeViewInfo>();

            //if (!isRootNode)
            //{
            //    tView = srcType.TreeView(tView);
            //    tView = src.TreeView(tView, false);
            //    tView = dal.TreeView(tView, false);
            //}
            //else
            //{
                tView = dal.TreeView(tView, true);
            //}

            return tView;
        }

        public void Insert(string code, string name, string descr, int parent, int source, string gfmis_code)
        {
            int chkError = dal.Insert(new ExpenseGroupInfo(0, code, name, descr, "", gfmis_code
                , new ExpenseGroupInfo(parent), new SourceInfo(source), new UserRecordInfo(1, null)));

            if (chkError == 0)
            {
                // Error
            }
        }

        public void Update(int seq, string code, string name, string descr, int parent, int source, string gfmis_code)
        {
            int chkError = dal.Update(new ExpenseGroupInfo(seq, code, name, descr, "", gfmis_code
                , new ExpenseGroupInfo(parent), new SourceInfo(source), new UserRecordInfo(null, 1)));

            if (chkError == 0)
            {
                // Error
            }
        }

        public void Delete(int seq)
        {
            int chkError = dal.Delete(seq);
        }

        public IList<ExpenseGroupInfo> Search(int seq)
        {
            return Search(seq, "", "", "", 0, 0);
        }

        public IList<ExpenseGroupInfo> Search(int seq, string code, string name, string descr, int parent, int source)
        {
            return dal.Search(new ExpenseGroupInfo(seq, code, name, descr, "", "", new ExpenseGroupInfo(parent), new SourceInfo(source), null));
        }
       public bool CheckDuplicateCode(string code)
       {
            return dal.CheckDuplicateCode(code);
       }
    }
}
